import socket
import time

class DictText():
	def __init__(self, text=None, dict=None):
		self.text = text
		self.dict = dict
		pass
		# text with format of : 00:00,50;
	def textTodict(self):
		tmp = self.text.split(';')
		self.dict = {}
		for t in tmp:
			t = t.split(',')
			if len(t) > 1:
				self.dict[t[0]] = int(t[1])
		return self.dict
	def dictTotext(self):
		self.text = ''
		for d in self.dict:
			self.text += d + ',' + str(self.dict[d]) + ';'
		self.text = self.text[:-1]
		return self.text

ssid_mac_1 = ['00:24:b2:27:ad:e6',
				'00:24:b2:7e:df:fc',
				'00:22:3f:33:06:a8',
				'00:22:3f:12:52:5e']
				
ssid_mac_2 = [ '1c:af:f7:a7:89:10',
				'00:1d:0f:66:e2:12',
				'00:0a:eb:e1:16:96',
				'74:ea:3a:60:86:f4']

count = 0
l = [0,0,0,0]
MAX_COUNT = 5				
				
def getRSSI():
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	s.bind(('127.0.0.1', 8000))
	data, addr =  s.recvfrom(1024)
	s.close()
	rssi_text = data
	DT = DictText(text = rssi_text)
	rssi_dict = DT.textTodict()
		
	i = 0
	for mac in ssid_mac_2:
		if mac in rssi_dict:
			l[i] += rssi_dict[mac]
		i = i + 1
	print l
	return l

while True:
	try:
		_l = getRSSI()
	except:
		print '-------'
	l = [0,0,0,0]
	time.sleep(2)